//
//  ParentFoucsListViewController.swift
//  BellManage
//
//  Created by Bestsch on 16/3/31.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class ParentFoucsListViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {

    var tableView: UITableView!
    
    var classid: String!
    var studentArray = NSMutableArray()
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.title = "家长关注"
        
        InitView()
    }

    func InitView() {
        tableView = UITableView.init(frame: CGRect(x: 0, y: 0, width: screenW, height: screenH))
        tableView.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
        self.view.addSubview(tableView)
        setUpRefresh()
    }
    func setUpRefresh() {
        tableView.header = MJRefreshNormalHeader.init(refreshingTarget: self, refreshingAction: #selector(ParentFoucsListViewController.getStudentlist))
        self.tableView.header.beginRefreshing()
    }
    /**
     获取学生关注亲数量
     */
    func getStudentlist() {
        let user = getUserPojo()
        let requestXML = requestHeader + "20</t><sch>" + user.schid + "</sch><class>" + classid + "</class></channel></rss>"
        let url = server + webappapi
        var result = HttpUtils.httpPostUTF(url, with: requestXML)
        if result != nil {
            result = result?.replacingOccurrences(of: "null", with: "\"\"")
            
            let array = JSON(data: (result?.data(using: String.Encoding.utf8))!)
            if array.count != 0 {
                studentArray = NSMutableArray()
                studentArray.addObjects(from: array.arrayValue)
            }
        }
        tableView.reloadData()
        tableView.header.endRefreshing()

    }
    /**
     高度
     
     - parameter tableView: tableview
     - parameter indexPath: item
     
     - returns: 高度
     */
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    /**
     多少行
     
     - parameter tableView: tableview
     - parameter section:
     
     - returns: 行数
     */
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return studentArray.count
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellIdentifier = "ClassCountTableViewCellIdentifier";
        
        let cell: StudentListTableViewCell = StudentListTableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: cellIdentifier)
         cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        cell.selectionStyle = UITableViewCellSelectionStyle.none;
        let dic = studentArray[indexPath.row] as! JSON
        var stuPhoto = dic["StuPhoto"].stringValue
        stuPhoto = stuPhoto.replacingOccurrences(of: "../..", with: "").replacingOccurrences(of: "../", with: "/view/")
        let stuName = dic["StuName"].stringValue
        let count = dic["AttCount"].stringValue
        
        cell.userTx.sd_setImage(with: URL.init(string: server + stuPhoto ), placeholderImage: UIImage.init(named: "touxiangm"))
        cell.userName.text = stuName
        cell.count.text = "关注亲:" + count
        
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }

    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
